﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Dqs_DAL.Migrations
{
    /// <inheritdoc />
    public partial class InitialCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "T_Admin",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Password = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    FullName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Phone = table.Column<string>(type: "nvarchar(13)", maxLength: 13, nullable: false),
                    Role = table.Column<int>(type: "int", maxLength: 1, nullable: false),
                    DelFlag = table.Column<int>(type: "int", maxLength: 1, nullable: false, defaultValue: 0)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Admin", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "T_Student",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    StuNum = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    UserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Password = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    FullName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Phone = table.Column<string>(type: "nvarchar(13)", maxLength: 13, nullable: false),
                    Role = table.Column<int>(type: "int", maxLength: 1, nullable: false),
                    DelFlag = table.Column<int>(type: "int", maxLength: 1, nullable: false, defaultValue: 0),
                    AttendCount = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
                    QuestionCount = table.Column<int>(type: "int", nullable: false, defaultValue: 0)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Student", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "T_Teacher",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Password = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    FullName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Phone = table.Column<string>(type: "nvarchar(13)", maxLength: 13, nullable: false),
                    Role = table.Column<int>(type: "int", maxLength: 1, nullable: false),
                    DelFlag = table.Column<int>(type: "int", maxLength: 1, nullable: false, defaultValue: 0),
                    TeaNum = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Teacher", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "T_Question",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Q = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
                    StudentId = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Question", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Question_T_Student_StudentId",
                        column: x => x.StudentId,
                        principalTable: "T_Student",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "T_Course",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CourseName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    TeachersId = table.Column<int>(type: "int", nullable: true),
                    StartTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    EndTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Course", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Course_T_Teacher_TeachersId",
                        column: x => x.TeachersId,
                        principalTable: "T_Teacher",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "T_QuestionReply",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Reply = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
                    QuestionId = table.Column<int>(type: "int", nullable: false),
                    StudentId = table.Column<int>(type: "int", nullable: true),
                    TeacherId = table.Column<int>(type: "int", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_QuestionReply", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_QuestionReply_T_Question_QuestionId",
                        column: x => x.QuestionId,
                        principalTable: "T_Question",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "T_Class",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false),
                    ClassName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    IsMultimedia = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    IsOccupied = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    MaxCount = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Class", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Class_T_Course_Id",
                        column: x => x.Id,
                        principalTable: "T_Course",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "T_Students_Courses",
                columns: table => new
                {
                    CourseListId = table.Column<int>(type: "int", nullable: false),
                    StudentListId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Students_Courses", x => new { x.CourseListId, x.StudentListId });
                    table.ForeignKey(
                        name: "FK_T_Students_Courses_T_Course_CourseListId",
                        column: x => x.CourseListId,
                        principalTable: "T_Course",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_T_Students_Courses_T_Student_StudentListId",
                        column: x => x.StudentListId,
                        principalTable: "T_Student",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "T_Seat",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    SeatNumber = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
                    IsOccupied = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    StudentID = table.Column<int>(type: "int", nullable: false),
                    ClassID = table.Column<int>(type: "int", nullable: false),
                    IsUse = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    ClassInfosId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_Seat", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_Seat_T_Class_ClassInfosId",
                        column: x => x.ClassInfosId,
                        principalTable: "T_Class",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_T_Admin_UserName",
                table: "T_Admin",
                column: "UserName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_T_Class_ClassName",
                table: "T_Class",
                column: "ClassName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_T_Course_TeachersId",
                table: "T_Course",
                column: "TeachersId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Question_StudentId",
                table: "T_Question",
                column: "StudentId");

            migrationBuilder.CreateIndex(
                name: "IX_T_QuestionReply_QuestionId",
                table: "T_QuestionReply",
                column: "QuestionId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Seat_ClassInfosId",
                table: "T_Seat",
                column: "ClassInfosId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Student_StuNum",
                table: "T_Student",
                column: "StuNum",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_T_Student_UserName",
                table: "T_Student",
                column: "UserName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_T_Students_Courses_StudentListId",
                table: "T_Students_Courses",
                column: "StudentListId");

            migrationBuilder.CreateIndex(
                name: "IX_T_Teacher_TeaNum",
                table: "T_Teacher",
                column: "TeaNum",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_T_Teacher_UserName",
                table: "T_Teacher",
                column: "UserName",
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "T_Admin");

            migrationBuilder.DropTable(
                name: "T_QuestionReply");

            migrationBuilder.DropTable(
                name: "T_Seat");

            migrationBuilder.DropTable(
                name: "T_Students_Courses");

            migrationBuilder.DropTable(
                name: "T_Question");

            migrationBuilder.DropTable(
                name: "T_Class");

            migrationBuilder.DropTable(
                name: "T_Student");

            migrationBuilder.DropTable(
                name: "T_Course");

            migrationBuilder.DropTable(
                name: "T_Teacher");
        }
    }
}
